package com.neusoft.neu24.nep.service.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neusoft.neu24.nep.entity.CommonResult;
import com.neusoft.neu24.nep.entity.Role;
import com.neusoft.neu24.nep.entity.Sysnode;
import com.neusoft.neu24.nep.mapper.RoleMapper;
import com.neusoft.neu24.nep.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;

import java.util.List;

@Service
public class RoleServiceImpl  extends ServiceImpl<RoleMapper , Role> implements IRoleService {

    @Autowired
    RoleMapper  roleMapper;

    @Override
    public CommonResult<Role> selectRoleById(int roleid) {
        Role role = baseMapper.selectById(roleid);

       try{
           CommonResult  result =  WebClient.create("http://localhost:8010")
                   .get()
                   .uri("/sysnode/q/by/1")
                   .accept(org.springframework.http.MediaType.APPLICATION_JSON)
                   .retrieve()
                   .bodyToMono(CommonResult.class)
                   .block();

           if (result.getCode() == 200){
               role.setSysnodes( (List<Sysnode>) result.getResult());
               return CommonResult.sucess(role);
           }
       }catch (Exception exception){
           System.out.println(exception.getMessage());
       }
        return CommonResult.filure();

    }
}





















